/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Affichage;

import Metier.Dialogue;
import Metier.Lieu;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JFrame;

/**
 *
 * @author Loick
 */
public class GestionLieux extends JFrame {
    
    private List<Lieu> c = new ArrayList<>();
    private Vector<String> v;
    private javax.swing.JButton BTNParcourirAdd;
    private javax.swing.JButton BTNParcourirMod;
    private javax.swing.JButton BTNAjouter;
    private javax.swing.JButton BTNModifier;
    private javax.swing.JLabel LBLDescriptionAdd;
    private javax.swing.JLabel LBLDescriptionAdd1;
    private javax.swing.JLabel LBLImageAdd;
    private javax.swing.JLabel LBLImageAdd1;
    private javax.swing.JLabel LBLLibelleAdd;
    private javax.swing.JLabel LBLLibelleAdd1;
    private javax.swing.JLabel LBLUrlAdd;
    private javax.swing.JLabel LBLUrlAdd1;
    private javax.swing.JList ListLieuSuprr;
    private javax.swing.JButton BTNSupprimer;
    private javax.swing.JTextArea TXTADescriptionAdd;
    private javax.swing.JTextArea TXTADescriptionMod;
    private javax.swing.JTextField TXTImageAdd;
    private javax.swing.JTextField TXTImageMod;
    private javax.swing.JTextField TXTLibelleAdd;
    private javax.swing.JComboBox CBModifierLieux;
    private javax.swing.JTextField TXTUrlAdd;
    private javax.swing.JTextField TXTUrlMod;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JTabbedPane jTabbedPane4;
    private Dialogue dial = new Dialogue();
    
    public GestionLieux() {
        jTabbedPane4 = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        LBLLibelleAdd = new javax.swing.JLabel();
        LBLUrlAdd = new javax.swing.JLabel();
        LBLImageAdd = new javax.swing.JLabel();
        LBLDescriptionAdd = new javax.swing.JLabel();
        TXTLibelleAdd = new javax.swing.JTextField();
        TXTUrlAdd = new javax.swing.JTextField();
        TXTImageAdd = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        TXTADescriptionAdd = new javax.swing.JTextArea();
        BTNAjouter = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        BTNParcourirAdd = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        LBLLibelleAdd1 = new javax.swing.JLabel();
        CBModifierLieux = new javax.swing.JComboBox();
        LBLUrlAdd1 = new javax.swing.JLabel();
        TXTUrlMod = new javax.swing.JTextField();
        LBLImageAdd1 = new javax.swing.JLabel();
        TXTImageMod = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        TXTADescriptionMod = new javax.swing.JTextArea();
        LBLDescriptionAdd1 = new javax.swing.JLabel();
        BTNModifier = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JSeparator();
        BTNParcourirMod = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        ListLieuSuprr = new javax.swing.JList();
        BTNSupprimer = new javax.swing.JButton();
        
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        
        LBLLibelleAdd.setText("Nom du lieu");
        
        LBLUrlAdd.setText("Acces au site du lieu");
        
        LBLImageAdd.setText("Image du lieu");
        
        LBLDescriptionAdd.setText("Description du lieu");
        
        TXTADescriptionAdd.setColumns(20);
        TXTADescriptionAdd.setRows(5);
        jScrollPane1.setViewportView(TXTADescriptionAdd);
        
        BTNAjouter.setText("Ajouter");
        BTNAjouter.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Dialogue passerlieu = new Dialogue();
                Lieu DefLieu = new Lieu();
                DefLieu.setLibelle(TXTLibelleAdd.getText());
                DefLieu.setCarte(TXTImageAdd.getText());
                DefLieu.setUrl(TXTUrlAdd.getText());
                DefLieu.setTexte(TXTADescriptionAdd.getText());
                
                passerlieu.insertLieu(DefLieu);
                dispose();
            }
        });
        
        jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);
        
        BTNParcourirAdd.setText("Parcourir");
        BTNParcourirAdd.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    JFileChooser Parcourir = new JFileChooser();
                    Parcourir.setFileSelectionMode(JFileChooser.FILES_ONLY);
                    
                    Parcourir.setAcceptAllFileFilterUsed(true);
                    
                    int Valretour = Parcourir.showOpenDialog(null);
                    if (Valretour == JFileChooser.APPROVE_OPTION) {
                        TXTImageAdd.setText(Parcourir.getSelectedFile().getName());
                    }
                    FileInputStream sourceFile = null;
                    FileOutputStream destiFile = null;
                    sourceFile = new FileInputStream(Parcourir.getSelectedFile().getAbsolutePath());
                    destiFile = new FileOutputStream("F:\\A2ProjetJava\\ProjetJava2clone\\mini-sig-java\\MiniSig\\" + Parcourir.getSelectedFile().getName());
                    byte buffer[] = new byte[512 * 1024];
                    int nbLecture;
                    try {
                        while ((nbLecture = sourceFile.read(buffer)) != -1) {
                            destiFile.write(buffer, 0, nbLecture);
                        }
                    } catch (IOException ex) {
                        Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
                    } finally {
                        try {
                            sourceFile.close();
                            destiFile.close();
                        } catch (IOException ex) {
                            Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }
                } catch (FileNotFoundException ex) {
                    Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
                }

//                JFileChooser Parcourir = new JFileChooser();
//                Parcourir.setFileSelectionMode(JFileChooser.FILES_ONLY);
//
//                Parcourir.setAcceptAllFileFilterUsed(true);
//
//                int Valretour = Parcourir.showOpenDialog(null);
//                if (Valretour == JFileChooser.APPROVE_OPTION) {
//                    TXTCheminLieu.setText(Parcourir.getSelectedFile().getName());
//                }

            }
        });
        
        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(LBLLibelleAdd)
                .addComponent(LBLImageAdd)
                .addComponent(LBLDescriptionAdd)
                .addComponent(LBLUrlAdd)
                .addComponent(BTNAjouter, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                .addComponent(jScrollPane1)
                .addComponent(TXTLibelleAdd)
                .addComponent(TXTUrlAdd)
                .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(TXTImageAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(BTNParcourirAdd, javax.swing.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE)))
                .addGap(16, 16, 16)));
        jPanel2Layout.setVerticalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(LBLLibelleAdd)
                .addComponent(TXTLibelleAdd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(LBLUrlAdd)
                .addComponent(TXTUrlAdd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(LBLImageAdd)
                .addComponent(TXTImageAdd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(BTNParcourirAdd))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(LBLDescriptionAdd)
                .addGap(18, 18, 18)
                .addComponent(BTNAjouter, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
        
        jTabbedPane4.addTab("Ajouter un lieu ", jPanel2);
        
        LBLLibelleAdd1.setText("Nom du lieu");
        
        LBLUrlAdd1.setText("Acces au site du lieu");
        
        LBLImageAdd1.setText("Image du lieu");
        
        TXTADescriptionMod.setColumns(20);
        TXTADescriptionMod.setRows(5);
        jScrollPane2.setViewportView(TXTADescriptionMod);
        
        LBLDescriptionAdd1.setText("Description du lieu");
        
        BTNModifier.setText("Modifier");
        
        
        List<Lieu> listlieu = dial.getUrlEtLibelleLieu();
        for (Lieu lieux : listlieu) {
            CBModifierLieux.addItem(lieux.getLibelle());
        }
        
        
        CBModifierLieux.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {

            }
        });
        
        jSeparator2.setOrientation(javax.swing.SwingConstants.VERTICAL);
        
        BTNParcourirMod.setText("Parcourir");
        
        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
                jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(LBLLibelleAdd1)
                .addComponent(LBLImageAdd1)
                .addComponent(LBLDescriptionAdd1)
                .addComponent(LBLUrlAdd1)
                .addComponent(BTNModifier, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                .addComponent(jScrollPane2)
                .addComponent(CBModifierLieux)
                .addComponent(TXTUrlMod)
                .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(TXTImageMod, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(BTNParcourirMod, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addGap(18, 18, 18)));
        jPanel4Layout.setVerticalGroup(
                jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel4Layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(LBLLibelleAdd1)
                .addComponent(CBModifierLieux, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(LBLUrlAdd1)
                .addComponent(TXTUrlMod, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(LBLImageAdd1)
                .addComponent(TXTImageMod, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(BTNParcourirMod))
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(LBLDescriptionAdd1)
                .addGap(18, 18, 18)
                .addComponent(BTNModifier, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
        
        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
                jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
        jPanel3Layout.setVerticalGroup(
                jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
        
        jTabbedPane4.addTab("Modifier un lieu", jPanel3);
        
        v = new Vector<String>();
        Dialogue resurl = new Dialogue();
        c = resurl.getUrlEtLibelleLieu();
        for (Lieu lieu : c) {
            v.add(lieu.getLibelle());
        }
        ListLieuSuprr.setListData(v);
        jScrollPane3.setViewportView(ListLieuSuprr);
        
        BTNSupprimer.setText("Supprimer");
        BTNSupprimer.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                for (Lieu lieu : c) {
                    if ((lieu.getLibelle()).equals(ListLieuSuprr.getSelectedValue())) {
                        Dialogue supr = new Dialogue();
                        supr.supprimerLieu(lieu);
                        
                        
                    }
                    
                }
                dispose();
            }
        });
        
        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 205, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(BTNSupprimer, javax.swing.GroupLayout.DEFAULT_SIZE, 115, Short.MAX_VALUE)
                .addGap(18, 18, 18)));
        jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 226, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(BTNSupprimer, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap()));
        
        jTabbedPane4.addTab("Supprimer un lieu", jPanel1);
        
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jTabbedPane4));
        layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jTabbedPane4));
        
        pack();
    }// </editor-fold>     
}
